﻿using ESP.Configuration;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ESP.Data
{
    public partial class Database
    {
        private static DatabaseHelper defaultInstance;
        static Database()
        {
            try
            {
                defaultInstance = new DatabaseHelper(ConfigurationManager.ConnectionStringName);
            }
            catch
            {
            }
        }

        public static void Initialize(string connectionString, string providerName)
        {
            defaultInstance = new DatabaseHelper(connectionString, providerName);
        }


        public static int ExecuteNonQuery(string commandText, CommandType commandType = CommandType.Text, params System.Data.IDataParameter[] parameters)
        {
            return defaultInstance.ExecuteNonQuery(commandText, commandType, parameters);
        }
        public static int ExecuteNonQuery(string commandText, CommandType commandType, IEnumerable<System.Data.IDataParameter> parameters)
        {
            return defaultInstance.ExecuteNonQuery(commandText, commandType, parameters);
        }

        public static DbDataReader ExecuteReader(string commandText, CommandType commandType = CommandType.Text, params System.Data.IDataParameter[] parameters)
        {
            return defaultInstance.ExecuteReader(commandText, commandType, parameters);
        }
        public static DbDataReader ExecuteReader(string commandText, CommandType commandType, IEnumerable<System.Data.IDataParameter> parameters)
        {
            return defaultInstance.ExecuteReader(commandText, commandType, parameters);
        }

        public static object ExecuteScalar(string commandText, CommandType commandType = CommandType.Text, params System.Data.IDataParameter[] parameters)
        {
            return defaultInstance.ExecuteScalar(commandText, commandType, parameters);
        }
        public static object ExecuteScalar(string commandText, CommandType commandType, IEnumerable<System.Data.IDataParameter> parameters)
        {
            return defaultInstance.ExecuteScalar(commandText, commandType, parameters);
        }

        public static DbParameter CreateInputParameter(string name, object value)
        {
            return defaultInstance.CreateInputParameter(name, value);
        }
        public static DbParameter CreateParameter()
        {
            return defaultInstance.CreateParameter();
        }

        public static IDataReader ExecuteReader(CommandInfo cmd)
        {
            return defaultInstance.ExecuteReader(cmd);
        }
        public static int ExecuteNonQuery(CommandInfo cmd)
        {
            return defaultInstance.ExecuteNonQuery(cmd);
        }
        public static object ExecuteScalar(CommandInfo cmd)
        {
            return defaultInstance.ExecuteScalar(cmd);
        }
    }
}
